x = input()
max=0
if len(x) != 4:    
    pass
else:
    s = list(x)
    for m in range(0, 3):        
        for i in range(2,int(s[m]+s[m+1])): 
            if int(s[m]+s[m+1]) % i == 0:                
                break 
        else:            
            if int(s[m]+s[m+1])>max:
                max = int(s[m]+s[m+1])    
    for k in s:
        for i in range(2, int(k)):            
            if int(k) % i == 0:
                break        
        else:
            if int(k)>max: 
                max=int(k)    
    for i in range(2, int(x)):
        if int(x)%i == 0:            
            break
    else:        
        if max< int(x):
            max = int(x)    
    for f in range(1,3):
        for i in range(2,int(s[f-1]+s[f]+s[f+1])):             
            if int(s[f-1]+s[f]+s[f+1]) % i == 0:
                break        
        else:
            if int(s[f-1]+s[f]+s[f+1])>max:                 
                max = int(s[f-1]+s[f]+s[f+1])
print(max)